package org.ruanjj.twoSum;

import java.util.HashMap;
import java.util.Map;

public class Solution {
    public int[] twoSum(int[] nums, int target) {
        int[] res = new int[2];
        Map<Integer, Integer> hashMap = new HashMap<>();
        for(int i=0; i<nums.length; i++){
            if(!hashMap.containsKey(Integer.valueOf(target-nums[i]))){
                hashMap.put(Integer.valueOf(nums[i]),Integer.valueOf(i));
            }else{
                res[0] = hashMap.get(Integer.valueOf(target-nums[i]));
                res[1] = i;
                break;
            }
        }

        return res;
    }
}
